<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('邮件系统')" />
	<th:block th:include="include :: list-css" />
	<link rel="stylesheet" th:href="@{/js/layuiadmin-1.2.1/lib/extend/wangEditor/wangEditor.min.css}" media="all"/>
	<style type="text/css">
		html{background: #ffffff}
		.layui-form-radio{margin-top: 0}
		.getUpload {cursor: pointer;height: 22px;display: block;margin-top: 10px;}
		.box11{background:#fffdfd;}
		.shadow{position:relative;}
		/*.shadow{position:relative;box-shadow:0 1px 4px rgba(0,0,0,.3),0 0 20px rgba(0,0,0,.1) inset}*/
		.shadow::after,.shadow::before{content:"";z-index:-1;bottom:26px;left:10px;width:50%;height:20%;box-shadow:0 15px 10px rgba(0,0,0,.7);transform:rotate(-3deg)}
		.shadow::after{right:10px;left:auto;transform:rotate(3deg)}
		.btn-list {height: auto;text-align: left;padding: 5px 0 10px 40px;margin: 0}
		.person_root {width: auto;margin-top: 4px;margin-left: 10px;border: 1px solid #0095e7;color: #0095e7;border-radius: 3px;display: block;float: left;border-radius:14px;}
		.person_root span:nth-child(1){width:auto;height:28px;line-height:28px;display:block;float:left;margin-left:10px;margin-right:0;border:0 none;padding-right:5px;color:#0095e7}
		.person_root i{width:20px;display:block;padding:0;float:left;line-height:28px;text-align:center;font-style:normal;text-indent:0;cursor:pointer}
		.toUser_D,.ccUser_D,.scUser_D,.mailLabel_D{position: absolute;width: 98%;top: 1px;left:1px;height: auto;}
		.toUser_D p,.ccUser_D p,.scUser_D p ,.mailLabel_D p {height: 38px;line-height: 38px;padding-left: 10px;color: #757575;}
		.getSelct{cursor: pointer;}
		.just_input{width: 2px;height:28px;border: none;float: left;margin-left: 4px}
		.input-clear{position: absolute;right: -17px;top: 9px;font-size: 15px;}
		.main-content{margin-left: -20px;min-height: 100%;padding: 0;margin-top: 10px;}
	</style>
</head>
<body>
<div class="main-content">
	<!--新建邮件-->
	<div class="shadow box11">
		<form class="layui-form" action="">
			<input type="hidden" name="fileMark" th:value="${mailContent['fileMark']}">
			<input type="hidden" id="nid" th:value="${mailContent['fileMark']}">
			<input type="hidden" name="fromUser" th:value="${mailContent['fromUser']}">
			<input type="hidden" name="fromDept" th:value="${mailContent['fromDept']}">
			<input type="hidden" name="fromDeptName" th:value="${mailContent['fromDeptName']}">
			<input type="hidden" name="fromCid" th:value="${mailContent['fromCid']}">
			<input type="hidden" name="fromCidName" th:value="${mailContent['fromCidName']}">
			<input type="hidden" name="guid" th:value="${mailContent['guid']}">
			<div class="layui-form-item btn-list" style="border-radius:10px 10px 0 0 ;">
				<div class="layui-btn layui-btn-danger layui-table-tools" onclick="savepost(1)" style="background: rgba(0,161,21,1) !important"><p class="dhicon dh-paper-plane-o" style="color:white;font-size:14px;"><span class="fa_span" style="color: #FFFFFF">发 送</span></p></div>
				<div class="layui-btn layui-table-tools importbtn-bg" onclick="savepost(0)" style="background: rgba(243,160,65,1) !important;"><p class="dhicon dh-cube" style="color:white;font-size:14px"><span class="fa_span" style="color: #FFFFFF">存草稿</span></p></div>
				<div class="layui-btn layui-table-tools importbtn-bg" onclick="getUpload('vHFilesDefault','Mail','',$('#fileFlag'));"><p class="dhicon dh-paperclip" style="color:white;font-size:14px"><span class="fa_span" id="fileFlag" style="color: #FFFFFF">附 件</span></p></div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="getSelct" data-for="toUser"><i class="dhicon dh-newspaper-o"></i>&nbsp;收件人：</span></label>
				<div class="layui-input-block toUser_box">
					<div class="toUser_D"><input class="just_input" type="text" data-from="toUser"></div>
					<input type="text" name="toUserName" id="toUserName" value="" class="layui-input get-more" data-for="toUser" style="color:#fff;" readonly/>
					<i class="layui-icon layui-icon-more getMore" data-for="toUser" ></i>
					<input type="hidden" name="toUser" id="toUser" value="" />
					<i class="dhicon dh-trash-o input-clear" title="清空" onclick="clearUser('toUser')" style="color:red;"></i>
				</div>
			</div>
			<div class="layui-form-item ccUser_box">
				<label class="layui-form-label"><span class="getSelct" data-for="ccUser"><i class="dhicon dh-newspaper-o"></i>&nbsp;抄送：</span></label>
				<div class="layui-input-block">
					<div class="ccUser_D"><input class="just_input" type="text" data-from="ccUser"></div>
					<input type="text" name="ccUserName" id="ccUserName" value="" class="layui-input get-more" data-for="ccUser" style="color:#fff;" readonly/>
					<i class="layui-icon layui-icon-more getMore" data-for="ccUser" ></i>
					<input type="hidden" name="ccUser" id="ccUser" value="" />
					<i class="dhicon dh-trash-o input-clear" title="清空" onclick="clearUser('ccUser')" style="color:red;"></i>
				</div>
			</div>
			<div class="layui-form-item" style="height: auto">
				<label class="layui-form-label">主题：</label>
				<div class="layui-input-block" style="text-align: left">
					<input type="text" name="mailSubject" id="mailSubject" class="layui-input">
					<!--					<span class="getUpload" onclick="getUpload('vHFilesDefault','Mail','',$('#fileFlag'));"><i class="dhicon dh-paperclip"></i> &nbsp;<font id="fileFlag">附件</font></span>-->
				</div>
			</div>
			<div class="layui-form-item" style="height: auto">
				<label class="layui-form-label">重要邮件：</label>
				<div class="layui-input-block" style="text-align: left">
					<input type="radio" name="important" value="1" title="是">
					<input type="radio" name="important" value="0" title="否" checked>
				</div>
			</div>
			<div class="layui-form-item" style="height: auto">
				<label class="layui-form-label">紧急程度：</label>
				<div class="layui-input-block" style="text-align: left">
					<input type="radio" name="urgentDegree" value="普通" title="普通" checked>
					<input type="radio" name="urgentDegree" value="加急" title="加急">
					<input type="radio" name="urgentDegree" value="特急" title="特急">
				</div>
			</div>
			<div class="layui-form-item" style="height: auto">
				<label class="layui-form-label">保留邮件：</label>
				<div class="layui-input-block" style="text-align: left">
					<input type="radio" name="perpetual" value="1" title="是" lay-filter="perpetual">
					<input type="radio" name="perpetual" value="0" title="否" checked lay-filter="perpetual">
					&nbsp;&nbsp;&nbsp;
					<span id="perpetual-0">【非保留邮件保留[[${mailDelDays}]]天（超期转已删除）】</span>
					<span id="perpetual-1" style="display: none">【永久保留邮件】</span>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="getSelct" data-for="mailLabel"><i class="dhicon dh-credit-card"></i>&nbsp;邮件标签：</span></label>
				<div class="layui-input-block">
					<div class="mailLabel_D"></div>
					<input type="text" name="mailLabel" id="mailLabel" value="" class="layui-input get-more" data-for="mailLabel" style="color:#fff;" readonly/>
					<i class="layui-icon layui-icon-more getMore" data-for="mailLabel" ></i>
					<i class="dhicon dh-trash-o input-clear" title="清空" onclick="clearUser('mailLabel')" style="color:red;"></i>
				</div>
			</div>
			<div class="layui-form-item contentBox" style="text-align: unset;">
				<label class="layui-form-label">正文：</label>
				<div class="layui-input-block">
					<div id="content">
					</div><br>
					<textarea id="mailContent" name="mailContent"  style="display: none"></textarea>
				</div>
			</div>
			<!--			<div class="layui-form-item" style="height: auto;">-->
			<!--				<label class="layui-form-label">发件人：</label>-->
			<!--				<div class="layui-input-block" style="text-align: left">-->
			<!--					<input type="text"  name="fromUserName" th:value="${mailContent['fromUserName']}" class="layui-input" readonly>-->
			<!--				</div>-->
			<!--			</div>-->
		</form>
	</div>
</div>

<script th:src="@{/js/jquery/jquery.min.js}"></script>
<script th:src="@{/js/jquery/jquery.cookie.js}"></script>
<script th:src="@{/js/layuiadmin-1.2.1/layui/layui.js?v=2}"></script>
<script th:src="@{/js/jquery/jquery.blockUI.min.js}"></script>
<script th:src="@{/dhecp/js/dh-common.js?v=53}"></script>
<script th:src="@{/dhecp/js/dh-ui.js?v=36}"></script>
<script th:src="@{/js/layuiadmin-1.2.1/lib/extend/wangEditor/wangEditor.min.js}"></script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var mailContent=[[${mailContent}]],
			pageType=[[${pageType}]],
			fromPageType=[[${fromPageType}]],
			moduleTable=[[${moduleTable}]];
	/*]]>*/
</script>
<script>
	$(".box11").css('height',$(window).height()-30);
	$(".contentBox").css('height',$(window).height()-436);
	$(".btn-list").css('background',parent.logo_color_rgba);
	var toUserName_obj=[],toUser_obj=[],ccUserName_obj=[],ccUser_obj=[],scUserName_obj=[],scUser_obj=[],mailLabel_obj=[];
	if(pageType == 'reply'){		//回复页面赋值
		$(".toUser_D").html('<span class="person_root"><span>'+mailContent['scUserName']+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="0" data-type="toUser"></i></span>');
		toUserName_obj.push(mailContent['scUserName']+';');
		toUser_obj.push(mailContent['scUser']+';');
		$("#toUserName").val(mailContent['scUserName']+';');
		$("#toUser").val(mailContent['scUser']+';');
		$("#mailSubject").val('回复：'+mailContent['mailSubject']);
		$("#fileFlag").html(mailContent['vHFilesDefault']);
		forContent();
	}else if(pageType == 'transport'){		//转发页面赋值
		$("#mailSubject").val('转发：'+mailContent['mailSubject']);
		$("#fileFlag").html(mailContent['vHFilesDefault']);
		forContent();
	}else if(pageType == 'edit'){		//编辑页面赋值
		forUser(mailContent['toUserName'],toUserName_obj,'toUserName','toUser','toUser_D');		//收件人名赋值
		forUser(mailContent['toUser'],toUser_obj,'toUser');										//收件人编号赋值
		forUser(mailContent['ccUserName'],ccUserName_obj,'ccUserName','ccUser','ccUser_D');		//抄送人名赋值
		forUser(mailContent['ccUser'],ccUser_obj,'ccUser');										//抄送人编号赋值
		forUser(mailContent['mailLabel'],mailLabel_obj,'mailLabel','mailLabel','mailLabel_D');										//邮件标签赋值

		$("#mailSubject").val(mailContent['mailSubject']);
		$("#content").html(mailContent['mailContent']);
		$("#fileFlag").html(mailContent['vHFilesDefault']);
		$("input[name=important][value=1]").attr("checked", mailContent.important ? true : false);
		$("input[name=important][value=0]").attr("checked", mailContent.important ? false : true);
		$("input[name=perpetual][value=1]").attr("checked", mailContent.perpetual ? true : false);
		if(mailContent.urgentDegree == "普通")$("input[name=urgentDegree][value='普通']").attr("checked", true);
		if(mailContent.urgentDegree == "加急")$("input[name=urgentDegree][value='加急']").attr("checked", true);
		if(mailContent.urgentDegree == "特急")$("input[name=urgentDegree][value='特急']").attr("checked", true);
	}
	//正文赋值
	function forContent(){
		console.log("mailContent",mailContent)
		$("#content").html('<br>'+mailContent['mailContent']+
				'<div style="background: #f3f1f1;padding:5px 6px;font-size: 14px;">' +
				'<p style="margin:2px 0;"><b>发件人：</b>'+mailContent['fromUserName']+'['+mailContent['fromUser']+'];</p>' +
				'<p style="margin:2px 0;"><b>发件时间：</b>'+mailContent['sendTime']+';</p>' +
				'<p style="margin:2px 0;"><b>收件人：</b>'+mailContent['toUserName']+';</p>' +
				'<p style="margin:2px 0;"><b>抄送人：</b>'+mailContent['ccUserName']+';</p>' +
				'<p style="margin:2px 0;"><b>主题：</b>'+mailContent['mailSubject']+';</p></div><br>'+'<div style="font-family: Arial Narrow;padding:2px 0 2px 0;"><hr style="border-top: 1px dotted;margin: 10px 1px;"></div>' );
	}
	/*
	* 收件人、抄送人、密送、邮件标签赋值
	* dataV  字符串值
	* forObj 目标对象 eg：toUser_obj
	* forField 目标字段
	* dataType 目标类型
	* forHtml  tag赋值
	* fromBook  true来自通讯录赋值
	* */
	function forUser(dataV,forObj,forField,dataType,forHtml='',fromBook = false){
		var namestr = '';
		if(fromBook){
			if($.inArray(dataV+';', forObj) == '-1'){
				forObj.push(dataV+';');
				$.each(forObj,function (i,v){
					if(v){
						if(forHtml)namestr += '<span class="person_root"><span>'+v.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i+'" data-type="'+dataType+'"></i></span>';
					}
				})
				var reg = new RegExp(",","g");
				$("#"+forField).val(forObj.toString().replace(reg,''));
			}else
				return false;
		}else{
			var str2obj = dataV.split(';');
			$.each(str2obj,function (i,v){
				if(v){
					forObj.push(v+';');
					if(forHtml)namestr += '<span class="person_root"><span>'+v+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i+'" data-type="'+dataType+'"></i></span>';
				}
			})
			$("#"+forField).val(dataV);
		}
		if(forField == 'toUserName'){
			namestr += '<input class="just_input" type="text" data-from="toUser">'
		}else if(forField == 'ccUserName'){
			namestr += '<input class="just_input" type="text" data-from="ccUser">'
		}
		if(forHtml)$("."+forHtml).html(namestr);
		if(forField == 'toUserName'){
			$(".toUser_D").parents(".layui-form-item").height($(".toUser_D").height()+5)
			$("#toUserName").height($(".toUser_D").height()+5)
		}else if(forField == 'ccUserName'){
			$(".ccUser_D").parents(".layui-form-item").height($(".ccUser_D").height()+5)
			$("#ccUserName").height($(".ccUser_D").height()+5)
		}
		boxHeight();
	}
	var $,layer,from,element;
	layui.use(['layer','element','form'], function () {
		$ = layui.jquery,
				layer = layui.layer,
				form = layui.form,
				element = layui.element;
		//监听保留邮件
		form.on('radio(perpetual)', function (data) {
			if(data.value == 1){
				$("#perpetual-1").show()
				$("#perpetual-0").hide()
			}else{
				$("#perpetual-1").hide()
				$("#perpetual-0").show()
			}
		});
	});
	<!--js初始化编辑器-->
	var E = window.wangEditor;
	var editor = new E('#content');
	var $mailContent = $('#mailContent')
	editor.config.height = $(window).height()-436;
	editor.config.uploadImgServer = '/system/fileinfo/uploadmailimg';
	editor.config.uploadImgParams = {
		moduleFile: 'mailImg',
		vType: 'MailImg',
		fileMark:'mailImg',
		fieldName:'mailImg'
	}
	editor.config.uploadFileName = 'file';
	editor.config.onchange = function (html) {
		// 第二步，监控变化，同步更新到 textarea
		$mailContent.val(html)
	}
	editor.create();
	$mailContent.val(editor.txt.html())

	$(".getMore, .getSelct").click(function(){
		var data_for= $(this).attr('data-for');
		var selectedObject = $("#"+data_for).val();
		if(data_for == 'mailLabel'){
			if(selectedObject) selectedObject = selectedObject.substring(0,selectedObject.length -1);
			var title = '选择邮件标签',url = "/system/mail/mailLabelSelectList?pagetype=checkbox&selectedObject="+selectedObject,areaObj = ['600px', '490px'];
		}else{
			var reg1 = new RegExp(";\\[user\\]","g"),reg2 = new RegExp("\\[user\\]","g");
			selectedObject = selectedObject.replace(reg1,',');
			selectedObject = selectedObject.replace(reg2,'');
			console.log('selectedObject---', selectedObject);
			var title = '选择对象',url = "/system/user/userselect?pagetype=checkbox&by=all&selectedUser="+selectedObject;
			var areaObj = ['1000px', '490px'];
			//var title = '选择对象',url = "/system/organization/orgObjectSelect?pagetype=checkbox&by=all&selectedObject="+selectedObject,areaObj = ['1000px', '490px'];
		}
		layer.open({
			type: 2//Page层类型
			,area: areaObj
			,offset: '10%'
			,title: title
			,shade: 0.6 //遮罩透明度
			,maxmin: true //允许全屏最小化
			,content: url
			,btn: ['确定', '关闭'] //只是为了演示
			,yes: function(index){
				var res = window["layui-layer-iframe" + index].callbackdata();
				if(res.length > 0){
					var reg = new RegExp(",","g");
					if(data_for == 'toUser'){
						toUserName_obj = [], toUser_obj = [];
						$.each(res,function (i,v) {
							toUserName_obj.push(v['userName']+' ['+v['userId']+'];');
							toUser_obj.push('[user]'+v['userId']+';');
						})
						var toUserNameStr = toUserName_obj.toString().replace(reg,'');
						var toUserStr = toUser_obj.toString().replace(reg,'');
						$("#toUserName").val(toUserNameStr.substring(0,toUserNameStr.length-1));
						$("#toUser").val(toUserStr.substring(0,toUserStr.length-1));
						$(".toUser_D").html('<input class="just_input" type="text" data-from="toUser">');
						$.each(toUserName_obj,function (i2,v2) {
							$(".toUser_D .just_input").before('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="toUser"></i></span>');
						})
						$(".toUser_D").parents(".layui-form-item").height($(".toUser_D").height()+5)
						$("#toUserName").height($(".toUser_D").height()+5)
					}
					/*
					if(data_for == 'toUser'){
						toUserName_obj = [], toUser_obj = [];
						$.each(res,function (i,v) {
							toUserName_obj.push(v['orgName']+' ['+v['orgid']+'];');
							toUser_obj.push('[' + v['orgKind'] + ']'+v['orgid']+';');
						})
						var toUserNameStr = toUserName_obj.toString().replace(reg,'');
						var toUserStr = toUser_obj.toString().replace(reg,'');
						console.log('toUserStr---', toUserStr);
						$("#toUserName").val(toUserNameStr.substring(0,toUserNameStr.length-1));
						$("#toUser").val(toUserStr.substring(0,toUserStr.length-1));
						$(".toUser_D").html('<input class="just_input" type="text" data-from="toUser">');
						$.each(toUserName_obj,function (i2,v2) {
							$(".toUser_D .just_input").before('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="toUser"></i></span>');
						})
						$(".toUser_D").parents(".layui-form-item").height($(".toUser_D").height()+5)
						$("#toUserName").height($(".toUser_D").height()+5)
					}
					*/
					else if(data_for == 'ccUser'){
						ccUserName_obj = [], ccUser_obj = [];
						$.each(res,function (i,v) {
							ccUserName_obj.push(v['userName']+' ['+v['userId']+'];');
							ccUser_obj.push('[user]'+v['userId']+';');
						})
						var ccUserNameStr = ccUserName_obj.toString().replace(reg,'');
						var ccUserStr = ccUser_obj.toString().replace(reg,'');
						$("#ccUserName").val(ccUserNameStr.substring(0,ccUserNameStr.length-1));
						$("#ccUser").val(ccUserStr.substring(0,ccUserStr.length-1));
						$(".ccUser_D").html('<input class="just_input" type="text" data-from="ccUser">');
						$.each(ccUserName_obj,function (i2,v2) {
							$(".ccUser_D .just_input").before('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="ccUser"></i></span>');
						})

						$(".ccUser_D").parents(".layui-form-item").height($(".ccUser_D").height()+5)
						$("#ccUserName").height($(".ccUser_D").height()+5)
					}
					/*
					else if(data_for == 'ccUser'){
						ccUserName_obj = [], ccUser_obj = [];
						$.each(res,function (i,v) {
							ccUserName_obj.push(v['orgName']+' ['+v['orgid']+'];');
							ccUser_obj.push('[' + v['orgKind'] + ']'+v['orgid']+';');
						})
						var ccUserNameStr = ccUserName_obj.toString().replace(reg,'');
						var ccUserStr = ccUser_obj.toString().replace(reg,'');
						$("#ccUserName").val(ccUserNameStr.substring(0,ccUserNameStr.length-1));
						$("#ccUser").val(ccUserStr.substring(0,ccUserStr.length-1));
						$(".ccUser_D").html('<input class="just_input" type="text" data-from="ccUser">');
						$.each(ccUserName_obj,function (i2,v2) {
							$(".ccUser_D .just_input").before('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="ccUser"></i></span>');
						})

						$(".ccUser_D").parents(".layui-form-item").height($(".ccUser_D").height()+5)
						$("#ccUserName").height($(".ccUser_D").height()+5)
					}
					*/
					else if(data_for == 'mailLabel'){
						mailLabel_obj = [];
						$.each(res,function (i,v) {
							mailLabel_obj.push(v['vname']+';');
						})
						var mailLabelStr = mailLabel_obj.toString().replace(reg,'');
						$("#mailLabel").val(mailLabelStr.substring(0,mailLabelStr.length-1));
						$(".mailLabel_D").html('');
						$.each(mailLabel_obj,function (i2,v2) {
							$(".mailLabel_D").append('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="mailLabel"></i></span>');
						})

						$(".mailLabel_D").parents(".layui-form-item").height($(".mailLabel_D").height()+5)
						$("#mailLabel").height($(".mailLabel_D").height()+5)
					}

					layer.closeAll();
					boxHeight();
				}else{
					layer.msg("请选择数据");
				}
			}
			,btn2: function(){
				layer.closeAll();
			}
		});
	})
	//点击收件人、抄送框，焦点
	var focus_obj = 'toUser';
	$(".toUser_box,.ccUser_box").click(function (){
		$(this).find(".just_input").focus();
		focus_obj = $(this).find(".just_input").attr("data-from");
	})
	//删除tag
	function close_span(obj){
		var reg = new RegExp(",","g");
		var oliid = $(obj).attr('oliid');
		data_type = $(obj).attr('data-type');
		if(data_type == 'toUser'){
			toUserName_obj.splice(oliid, 1);
			toUser_obj.splice(oliid, 1);
			var toUserNameStr = toUserName_obj.toString().replace(reg,'');
			var toUserStr = toUser_obj.toString().replace(reg,'');
			$("#toUserName").val(toUserNameStr.substring(0,toUserNameStr.length-1));
			$("#toUser").val(toUserStr.substring(0,toUserStr.length-1));
			$(".toUser_D").html('<input class="just_input" type="text" data-from="toUser">');
			$.each(toUserName_obj,function (i2,v2) {
				$(".toUser_D .just_input").before('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="'+data_type+'"></i></span>');
			})
			if (toUserName_obj.length > 0){
				$(".toUser_D").parents(".layui-form-item").height($(".toUser_D").height()+5);
				$("#toUserName").height($(".toUser_D").height()+5);
			}
			focus_obj = 'toUser';
		}else if(data_type == 'ccUser'){
			ccUserName_obj.splice(oliid, 1);
			ccUser_obj.splice(oliid, 1);
			var ccUserNameStr = ccUserName_obj.toString().replace(reg,'');
			var ccUserStr = ccUser_obj.toString().replace(reg,'');
			$("#ccUserName").val(ccUserNameStr.substring(0,ccUserNameStr.length-1));
			$("#ccUser").val(ccUserStr.substring(0,ccUserStr.length-1));
			$(".ccUser_D").html('<input class="just_input" type="text" data-from="ccUser">');
			$.each(ccUserName_obj,function (i2,v2) {
				$(".ccUser_D .just_input").before('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="'+data_type+'"></i></span>');
			})
			if (ccUserName_obj.length > 0){
				$(".ccUser_D").parents(".layui-form-item").height($(".ccUser_D").height()+5)
				$("#ccUserName").height($(".ccUser_D").height()+5)
			}
			focus_obj = 'ccUser';
		}else if(data_type == 'mailLabel'){
			mailLabel_obj.splice(oliid, 1);
			var mailLabelStr = mailLabel_obj.toString().replace(reg,'');
			$("#mailLabel").val(mailLabelStr.substring(0,mailLabelStr.length-1));
			$(".mailLabel_D").html('');
			$.each(mailLabel_obj,function (i2,v2) {
				$(".mailLabel_D").append('<span class="person_root"><span>'+v2.replace(';','')+'</span><i class="close dhicon dh-zu4186" onclick="close_span(this)" oliid="'+i2+'" data-type="'+data_type+'"></i></span>');
			})
			if (mailLabel_obj.length > 0) {
				$(".mailLabel_D").parents(".layui-form-item").height($(".mailLabel_D").height() + 5)
				$("#mailLabel").height($(".mailLabel_D").height() + 5)
			}
		}
		boxHeight();
	}
	// 清空用户
	function clearUser(foruser){
		if(foruser == 'toUser'){
			toUserName_obj = [];
			toUser_obj = [];
			$("#toUserName").val('');
			$("#toUser").val('');
			$(".toUser_D").html('<input class="just_input" type="text" data-from="toUser">');
			$(".toUser_D").parents(".layui-form-item").height("30px");
			$("#toUserName").height("30px");
		}else if(foruser == 'ccUser'){
			ccUserName_obj = [];
			ccUser_obj = [];
			$("#ccUserName").val('');
			$("#ccUser").val('');
			$(".ccUser_D").html('<input class="just_input" type="text" data-from="ccUser">');
			$(".ccUser_D").parents(".layui-form-item").height("30px")
			$("#ccUserName").height("30px")
		}else if(foruser == 'mailLabel'){
			mailLabel_obj = [];
			$("#mailLabel").val('');
			$(".mailLabel_D").html('');
			$(".mailLabel_D").parents(".layui-form-item").height("30px")
			$("#mailLabel").height("30px")
		}
		boxHeight();
	}
	function savepost(mailType){
		if(!$("#toUser").val()){
			layer.msg("请选择收件人");
			return false;
		}
		if(!$("#mailSubject").val()){
			layer.msg("请填写主题");
			return false;
		}
		if(pageType == 'transport')$("[name='guid']").val('');
		if(mailType == 0){
			var url = '/system/mail/savepost'
		}else if(mailType == 1){
			var url = '/system/mail/sendpost'
		}
		var postData = {'infoItems':JSON.stringify([$(".layui-form").serializeFormToJson()])},rflag = false;
		$.operate.post(url, postData, function(res){
			if(res.code == 0){
				//更新列表显示数量
				parent.refreshMail();
				var userList = res.data.split(',');
				$.each(userList,function (i, v){
					parent.parent.sendMessage(v,'<p>您有新邮件,请及时查看哦！</p><p>主题：'+$("#mailSubject").val()+'</p>');
				})
				rflag = true;
			}
		},false);
		if(rflag && mailType == 1){
			layer.msg('操作成功', {
				icon: '1', offset: '10%', shift: 5,
				time: 20000, //20s后自动关闭
				btn: ['新建邮件', '返回列表'],
				btn1: function(){
					window.location.href = "/system/mail/edit?pageType=add&fromPageType=outbox";
				},
				btn2: function(){
					window.location.href = "/system/mail/mailList?pageType="+fromPageType;
					$("body",parent.document).find(".link-book").css("display","none");
					$("body",parent.document).find("#search-form").css("display","block");
					parent.treeReload();
				}
			});
		}
	}
	//更新页面高度
	function boxHeight(){
		$(".box11").css('height',$(".layui-form").height()+50);
	}
</script>
</body>
</html>